﻿using System;
using App_Code.Helpers;
using VisualCron;

namespace App_Code.Objects
{
    /// <summary>
    /// Summary description for TaskDTO
    /// </summary>
    public class TaskDTO
    {
        public string TaskId {get; set; }

        public string TaskName { get; set; }

        public string Active { get; set; }

        public string JobId { get; set; }

        public string Result { get; set; }

        public string TaskType { get; set; }

        public DateTime LastRun { get; set; }

        public int Order { get; set; }

        public string LastRunStr
        {
            get { return LastRun.ToString(PageHelper.CurrentUserDateTimeFormat()); }
        }

        public TaskDTO(TaskClass task, bool isTaskRunning)
        {
            this.TaskId = task.Id;
            this.TaskName = task.Name;
            this.Active = task.Stats.Active ? "Active" : "Inactive";

            Result = (task.Stats.ExitCode != 0)
                         ? "Failure"
                         : isTaskRunning
                               ? "Running"
                               : "Success";

            TaskType = task.TaskType.ToString();
   
            LastRun = task.Stats.DateLastExecution;

            Order = task.Order;

            this.JobId = task.JobId;
        }
    }
}